package org.algorithm.biubiu.wheel_1.数组.三月.第三周;

/**
 * @date 2022/03/17 10:08 PM
 * @description: 周五作业
 *
 *
 * url: https://leetcode-cn.com/problems/container-with-most-water/
 * 结题参考 https://leetcode-cn.com/problems/container-with-most-water/solution/container-with-most-water-shuang-zhi-zhen-fa-yi-do/
 */
public class 盛最多水的容器 {

    public static void main(String[] args) {
        int[] nums = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(nums));
    }


    /**
     左右指针 滑动窗口 求差值最小的区域
     */
    public static int maxArea(int[] height) {
        if(height==null){
            return -1;
        }
        int left = 0;
        int res = 0;
        for(int right=height.length-1;right>0&&right>left;){
            int hei =  Math.min(height[left],height[right])*(right-left);
            res = Math.max(hei,res);
            if( height[right]<=height[left]){
                right--;
            }else{
                left++;
            }
        }
        return res;

    }


}
